import pymysql

if __name__ == '__main__':
    # #连接数据库
    # conn = pymysql.connections.Connection(host="127.0.0.1", port=3306, user="root", password="root", db="shop")
    # #定义sql
    # sql="select * from user"
    # #获取游标对象
    # cursor = conn.cursor()
    # #执行sql
    # result=cursor.execute(sql)
    # #查询
    # n=cursor.fetchmany(10)
    # print(n)
    # #关闭连接
    # cursor.close()
    # conn.close()

    #连接数据库
    conn = pymysql.connections.Connection(host="127.0.0.1", port=3306, user="root", password="root", db="shop")
    #定义sql
    sql="insert into user (username,password) values (%s,%s)"
    #获取游标对象
    cursor = conn.cursor()
    #执行sql
    result2=cursor.execute(sql,("admin","admin123"))
    #提交事务
    conn.commit()
    #关闭连接
    cursor.close()
    conn.close()

